package com.beautify.qrcode.constants;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * 图元枚举
 *
 *
 * @author keia
 * @since 2022/1/13 20:21
 */
public enum StructEnum {
    /**
     * 宽1 高n
     */
    OneByOne("1_1","1_1.bmp",new Point(1,1)),
    OneByTwo("1_2","1_2.bmp",new Point(1,2)),
    OneByThree("1_3","1_3.bmp",new Point(1,3)),
    OneByFour("1_4","1_4.bmp",new Point(1,4)),
    OneByFive("1_5","1_5.bmp",new Point(1,5)),
    OneBySix("1_6","1_6.bmp",new Point(1,6)),
    OneBySeven("1_7","1_7.bmp",new Point(1,7)),

    /**
     * 宽2 高n
     */
    TwoByOne("2_1","2_1.bmp",new Point(2,1)),
    TwoByTwo("2_2","2_2.bmp",new Point(2,2)),
    TwoByThree("2_3","2_3.bmp",new Point(2,3)),
    TwoByFour("2_4","2_4.bmp",new Point(2,4)),
    TwoByFive("2_5","2_5.bmp",new Point(2,5)),
    TwoBySix("2_6","2_6.bmp",new Point(2,6)),
    TwoBySeven("2_7","2_7.bmp",new Point(2,7)),

    /**
     * 宽3 高n
     */
    ThreeByOne("3_1","3_1.bmp",new Point(3,1)),
    ThreeByTwo("3_2","3_2.bmp",new Point(3,2)),
    ThreeByThree("3_3","3_3.bmp",new Point(3,3)),
    ThreeByFour("3_4","3_4.bmp",new Point(3,4)),
    ThreeByFive("3_5","3_5.bmp",new Point(3,5)),
    ThreeBySix("3_6","3_6.bmp",new Point(3,6)),
    ThreeBySeven("3_7","3_7.bmp",new Point(3,7)),

    /**
     * 宽4 高n
     */
    FourByOne("4_1","4_1.bmp",new Point(4,1)),
    FourByTwo("4_2","4_2.bmp",new Point(4,2)),

    /**
     * 宽5 高n
     */
    FiveByOne("5_1","5_1.bmp",new Point(5,1)),
    FiveByTwo("5_2","5_2.bmp",new Point(5,2)),

    /**
     * 宽6 高n
     */
    SixByOne("6_1","6_1.bmp",new Point(6,1)),
    SixByTwo("6_2","6_2.bmp",new Point(6,2)),

    /**
     * 眼睛
     */
    Eye("7_7","7_7.bmp",new Point(7,7)),
    ;

    private String type;
    private String name;

    /**
     * 比对字符串，用于将模板图元替换到黑白二维码上
     */
    private String str = "";
    private Point point;

    StructEnum(String type, String name, Point point) {
        this.type = type;
        this.name = name;

        for(int x=0; x < point.x; x++) {
            for(int y=0;y <point.y; y++) {
                str = str + PointEnum.POINT_1.getType();
            }
            str = str + PointEnum.POINT_0.getType();
        }
        this.point = point;
    }

    private static final Map<String,StructEnum> ALL_STRUCT_MAP = new HashMap<>();
    static {
        for(StructEnum value : StructEnum.values()){
            ALL_STRUCT_MAP.put(value.getName(),value);
            System.out.println("============"+value.getName());
        }
    }

    public static StructEnum getStructByName(String name){
        return ALL_STRUCT_MAP.get(name);
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public Point getPoint() {
        return point;
    }

    public String getStr() {
        return str;
    }
}
